const judgeDataType = require('./judgeDataType')

// 拆分参数
module.exports = params => {
    const newParams = params
    // 分页参数
    const pageParams = {
        currentPage: params.currentPage,
        currentSize: params.currentSize
    };
    // 删除分页相关参数
    ['total', 'currentPage', 'currentSize'].forEach(Reflect.deleteProperty.bind(null, newParams))
    // 判断是否存在其他非空参数
    const searchParams = {}
    Object.keys(newParams).forEach(item => {
        if (judgeDataType(newParams[item]) === 'array') {
            if (newParams[item].length) searchParams[item] = newParams[item]
        } else if (newParams[item] !== null && newParams[item] !== undefined && newParams[item] !== ''){
            searchParams[item] = newParams[item]
        }
    })
    // 如果存在其他非空参数
    if (Object.keys(searchParams).length) {
        return {
            pageParams,
            // 其他参数
            otherParams: {
                paramsLength: Object.keys(searchParams).length,
                paramsValue: searchParams
            }
        }
    } else {
        return {
            pageParams,
            otherParams: null
        }
    }
}
